# 修复前端项目依赖问题
Write-Host "正在修复前端项目依赖问题..." -ForegroundColor Green

# 1. 清理现有的 node_modules 和 package-lock.json
Write-Host "1. 清理现有的 node_modules 和 package-lock.json" -ForegroundColor Yellow
if (Test-Path "node_modules") {
    Remove-Item -Recurse -Force "node_modules"
    Write-Host "   ✓ 已删除 node_modules 目录" -ForegroundColor Green
}

if (Test-Path "package-lock.json") {
    Remove-Item -Force "package-lock.json"
    Write-Host "   ✓ 已删除 package-lock.json 文件" -ForegroundColor Green
}

# 2. 清理 npm 缓存
Write-Host "2. 清理 npm 缓存" -ForegroundColor Yellow
npm cache clean --force
Write-Host "   ✓ npm 缓存已清理" -ForegroundColor Green

# 3. 重新安装依赖
Write-Host "3. 重新安装依赖" -ForegroundColor Yellow
npm install
Write-Host "   ✓ 依赖安装完成" -ForegroundColor Green

# 4. 验证 axios 是否已安装
Write-Host "4. 验证 axios 是否已安装" -ForegroundColor Yellow
if (Test-Path "node_modules\axios") {
    Write-Host "   ✓ axios 已成功安装" -ForegroundColor Green
} else {
    Write-Host "   ✗ axios 安装失败，尝试手动安装..." -ForegroundColor Red
    npm install axios@^1.6.0
    if (Test-Path "node_modules\axios") {
        Write-Host "   ✓ axios 手动安装成功" -ForegroundColor Green
    } else {
        Write-Host "   ✗ axios 安装仍然失败" -ForegroundColor Red
    }
}

# 5. 检查其他关键依赖
Write-Host "5. 检查其他关键依赖" -ForegroundColor Yellow
$dependencies = @("vue", "vue-router", "pinia", "element-plus", "chart.js")
foreach ($dep in $dependencies) {
    if (Test-Path "node_modules\$dep") {
        Write-Host "   ✓ $dep 已安装" -ForegroundColor Green
    } else {
        Write-Host "   ✗ $dep 未安装" -ForegroundColor Red
    }
}

Write-Host "`n依赖修复完成！现在可以尝试启动开发服务器。" -ForegroundColor Green
Write-Host "运行命令: npm run serve" -ForegroundColor Cyan
